﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.MediaCenter.Hosting;

namespace RMC.Commands
{
	internal class ButtonCommand : ICommand
	{

		#region ICommand Members

		public string Syntax
		{
			get { return "button <up|down|left|right|ok|info|back>"; }
		}

		public string Help
		{
			get { return @"button <up|down|left|right|ok|info|back>"; }
		}

		public CommandResult Execute(string args)
		{
			if (args.Equals("up", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x26);
			}
			else if (args.Equals("down", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x28);
			}
			else if (args.Equals("left", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x25);
			}
			else if (args.Equals("right", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x27);
			}
			else if (args.Equals("ok", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x0D);
			}
			else if (args.Equals("back", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x08);
			}
			else if (args.Equals("info", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('D', false, true, false);//0x5D
			}
			else if (args.Equals("play", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('P', true, true, false);
			}
				else if (args.Equals("pause", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('P', false, true, false);
			}
			else if (args.Equals("stop", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('S', true, true, false);
			}
			else if (args.Equals("skipback", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('B', false, true, false);
			}
			else if (args.Equals("skipfwd", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('F', false, true, false);
			}
			else if (args.Equals("rew", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('B', true, true, false);
			}
			else if (args.Equals("fwd", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd('Z', true, true, false);
			}
			else if (args.Equals("channelup", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x21);
			}
			else if (args.Equals("channeldown", StringComparison.CurrentCultureIgnoreCase))
			{
				return Win32Helpers.SendKeyCmd(0x22);
			}
			CommandResult cr = new CommandResult();
			cr.Type = CommandResultType.BadArguments;
			return cr;
		}

		#endregion
	}
}
